import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import Login from "../views/Login.vue";
import good from "./goods.js"; //商品管理
import operat from "./operate.js"; //运营管理
import promotio from "./promotion.js"; //推广管理
import syste from "./system.js"; //系统管理
import homepage from "./homepage.js"; //首页内容

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    component: Login,
    meta: [{ name: "登录" }]
  },
  {
    path: "/Home",
    component: Home,
    redirect: "/homepag", //默认跳转
    children: [...homepage]
  },
  {
    //商品管理
    path: "/goods",
    component: Home,
    name: "商品管理",
    children: [...good]
  },
  {
    //运营管理
    path: "/operate",
    component: Home,
    name: "运营管理",
    children: [...operat]
  },
  {
    //推广管理
    path: "/promotion",
    component: Home,
    name: "推广管理",
    children: [...promotio]
  },
  {
    //系统管理
    path: "/system",
    component: Home,
    name: "系统管理",
    children: [...syste]
  }
];

//防止多次点击路由而产生报错
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

const router = new VueRouter({
  routes
});

export default router;
